﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Xml.Serialization;
using System.Xml;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using MySql.Data.MySqlClient;
using System.Configuration;

namespace SecurityDev
{
    public partial class LoginForm : Form
    {
        public bool IsAdmin { get; private set; }

        OutpostDS.usersDataTable usersDT;
        OutpostDSTableAdapters.usersTableAdapter usersAdapter;

        public string UserName
        {
            get
            {
                return userNameTextBox.Text;
            }
        }

        public LoginForm()
        {
            InitializeComponent();
            this.userNameTextBox.Text = "andrey";
            this.passTextBox.Text = "123";

            usersAdapter = new OutpostDSTableAdapters.usersTableAdapter();
            try
            {
                usersDT = usersAdapter.GetData();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                Environment.Exit(0);
            }
            
        }

        private void loginButton_Click(object sender, EventArgs e)
        {
            var user = (from u in usersDT
                        where u.UserName == userNameTextBox.Text && u.UserPass == passTextBox.Text
                        select u).FirstOrDefault();
            if (user != null)
            {
                if (user.IsAdmin == 1)
                {
                    IsAdmin = true;
                }
                this.Close();                
            }
            else
            {
                label3.Visible = true;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Environment.Exit(0);
        }

    }
}
